package com.qishanor.system.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qishanor.framework.util.R;
import com.qishanor.system.model.GenDatasource;
import com.qishanor.system.service.GenDatasourceService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 数据源管理
 *
 */
@RestController
@AllArgsConstructor
@RequestMapping("/api/gen/datasource")
public class GenDatasourceController {

	private final GenDatasourceService datasourceService;



	@GetMapping("/page")
	public R getSysDatasourceConfPage(Page page, GenDatasource datasourceConf) {
		return R.ok(datasourceService.page(page, Wrappers.query(datasourceConf)));
	}


	/**
	 * 通过id查询数据源表
	 * @param id id
	 * @return R
	 */
	@GetMapping("/{id}")
	public R getById(@PathVariable("id") Integer id) {
		return R.ok(datasourceService.getById(id));
	}

	/**
	 * 新增数据源表
	 * @param datasourceConf 数据源表
	 * @return R
	 */
	@PostMapping
	public R save(@RequestBody GenDatasource datasourceConf) {
		return R.ok(datasourceService.saveDsByEnc(datasourceConf));
	}

	/**
	 * 修改数据源表
	 * @param conf 数据源表
	 * @return R
	 */

	@PutMapping
	public R updateById(@RequestBody GenDatasource conf) {
		return R.ok(datasourceService.updateDsByEnc(conf));
	}

	/**
	 * 通过id删除数据源表
	 * @param id id
	 * @return R
	 */
	@DeleteMapping("/{id}")
	public R removeById(@PathVariable Integer id) {
		return R.ok(datasourceService.removeByDsId(id));
	}

}
